//
//  Person.m
//  02-ClassAndCode
//
//  Created by dllo on 16/7/5.
//  Copyright © 2016年 dllo. All rights reserved.
//

//
//  Person.m
//  OC02_类和对象
//
//  Created by Hanlingyu on 16/7/5.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "Person.h"

@implementation Person


- (void)sleep:(NSInteger)time {
    // NSLog 属于C语言的函数
    NSLog(@"这个人睡了%ld年", time);
    
}

- (void)setName:(NSString *)name {
    _name = name;
}


- (void)setAge:(NSInteger)age {
    _age = age;
}
-(NSString *)name{
    return [[_name retain] autorelease];
}
- (NSInteger)age {
    return _age;
}
//实现大括号前，要加空格
//指派初始化方法：无论点用那个初始化方法，都会执行的初始化方法，称为指派初始化方法
//便利构造器
- (id)initWithName:(NSString *)name age:(NSInteger)age {
    self = [super init];
    if (self) {
        _name = name;
        _age = age;
    }
    return self;
}
-(id)initWithAge:(NSInteger)age {
    return [self initWithName:nil age:10];
}
+ (id)personOfName:(NSString *)name age:(NSInteger)age {
    return [[[Person alloc]initWithName:name age:age]autorelease];
}
//
//- (instancetype)initWithName:(NSString *)name age:(NSInteger)age {
//    
//    self = [super init];
//    if (self) {
//        _name = name;
//        _age = age;
//    }
//    
//    return self;
//}

//+ (instancetype)personOfName:(NSString *)name age:(NSInteger)age {
//    
//    Person *per = [[Person alloc] initWithName:name age:age];
//    return per;
//    
//}



@end